<?php namespace App\Services;

use App\Facades\Infra\TourismRecommendManager;
use App\Exceptions\DataBaseException;

class TourismService{
	/**
	 * 获取旅游指南
	 */
	public function getTourism(){
		return TourismRecommendManager::getTourismRecommends($this->formatConditions());
	}

	/**
	 * 修改旅游指南
	 */
	public function updateTourism($data){
		TourismRecommendManager::updateTourismRecommend($this->formatConditions(),$data);
	}

	/**
	 * 新增旅游指南
	 */
	public function createTourism($data){
		if($this->getTourism() != null){
			throw new DataBaseException('数据已存在');
		}

		TourismRecommendManager::createTourismRecommend($this->formatData($data));

		return;
	}

	/**
	 * 组成旅游指南条件
	 */
	private function formatConditions(){
		$conditions['hotel_id'] = \Auth::user()->id;

		return $conditions;
	}

	/**
	 * 组成新增数据
	 */
	private function formatData($data){
		$data['hotel_id'] = \Auth::user()->id;

		return $data;
	}
}